package com.yc.common.exceptions.captcha;

import com.yc.common.constant.HttpStatus;
import com.yc.common.enums.CaptchaType;
import com.yc.common.exceptions.ServiceException;
import lombok.Getter;
import lombok.Setter;

/**
 * 验证码获取过于频繁异常类
 * @Author YanChen
 * @Date 2025/4/24 15:15
 */
@Getter
@Setter
public class CaptchaTooFrequentException extends ServiceException {

    private static final long serialVersionUID = 1L;

    /**
     * 验证码类型
     */
    private CaptchaType captchaType;

    /**
     * 上次获取时间
     */
    private Long lastRequestTime;

    /**
     * 冷却时间（毫秒）
     */
    private Long cooldownTime;

    /**
     * 剩余冷却时间（毫秒）
     */
    private Long remainingCooldown;

    /**
     * 错误代码
     */
    private String errorCode;

    /**
     * 默认构造函数
     */
    public CaptchaTooFrequentException() {
        super("验证码获取过于频繁，请稍后再试", HttpStatus.BAD_REQUEST);
        this.captchaType = CaptchaType.IMAGE;
        this.errorCode = "CAPTCHA_TOO_FREQUENT";
    }

    /**
     * 使用自定义消息构造
     *
     * @param message 错误消息
     */
    public CaptchaTooFrequentException(String message) {
        super(message, HttpStatus.BAD_REQUEST);
        this.captchaType = CaptchaType.IMAGE;
        this.errorCode = "CAPTCHA_TOO_FREQUENT";
    }

    /**
     * 完整构造函数
     *
     * @param message           错误消息
     * @param captchaType       验证码类型
     * @param lastRequestTime   上次请求时间
     * @param cooldownTime      冷却时间
     * @param remainingCooldown 剩余冷却时间
     */
    public CaptchaTooFrequentException(String message, CaptchaType captchaType,
                                       Long lastRequestTime, Long cooldownTime, Long remainingCooldown) {
        super(message, HttpStatus.BAD_REQUEST);
        this.captchaType = captchaType;
        this.lastRequestTime = lastRequestTime;
        this.cooldownTime = cooldownTime;
        this.remainingCooldown = remainingCooldown;
        this.errorCode = "CAPTCHA_TOO_FREQUENT";
    }

    /**
     * 带错误代码的构造函数
     *
     * @param message   错误消息
     * @param errorCode 错误代码
     */
    public CaptchaTooFrequentException(String message, String errorCode) {
        super(message, HttpStatus.BAD_REQUEST);
        this.captchaType = CaptchaType.IMAGE;
        this.errorCode = errorCode;
    }
}